#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {

	vector<pair<int,int>> vecArr;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int s,e;
		cin>>s>>e;
		vecArr.push_back({s,e});
	}
	sort(vecArr.begin(),vecArr.end(),[](const pair<int,int>& p1,const pair<int,int>& p2){
		return p1.second<p2.second;	
	});
	int right=0;
	int nCnt=0;
	for(int i=0;i<n;++i){
		if(right<=vecArr[i].first){
			//cout<<vecArr[i].first<<' '<<vecArr[i].second<<endl;
			++nCnt;
			right=vecArr[i].second;
		}
	}
	cout<<nCnt<<endl;
	
	return 0;

}
